<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout" layout:decorate="~{layouts/main}">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div layout:fragment="content" style="width: 704px">
    <table class="layui-hide" id="list" lay-filter="list"></table>
    <script type="text/html" id="bar">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
</div>

</body>
<th:block layout:fragment="pageScripts">
    <script th:inline="javascript">
        var deleteUrl = /*[[@{/user/delete/}]]*/;
        var showUrl = /*[[@{/user/show/}]]*/;
        layui.use('table', function(){
            var table = layui.table;
            table.render({
                elem: '#list'
                ,url: /*[[@{/user/list}]]*/''
                ,cols: [
                    [
                        {field:'id', width:150, title: 'ID'}
                        ,{field:'loginName', width:200, title: '账号'}
                        ,{field:'name', width:200, title: '用户名'}
                        ,{field:'right', width:200, align:'center', toolbar: '#bar',fixed:'right'}
                    ]
                ]
                ,page: true
            });
            //监听工具条
            table.on('tool(list)', function(obj){
                var data = obj.data;
                if(obj.event === 'detail'){
                    layer.msg('ID：'+ data.id + ' 的查看操作');
                } else if(obj.event === 'del'){
                    layer.confirm('真的删除行么', function(index){
                        $.ajax({
                            type: "POST",
                            url: deleteUrl+data.id,
                            success: function (result) {
                                if (result.state == '200'){
                                    layer.alert(result.msg, {
                                        skin: 'layui-layer-molv'
                                        , closeBtn: 0
                                    }, function(){window.location.reload();})
                                }
                            }
                        });
                        layer.close(index);
                    });
                } else if(obj.event === 'edit'){
                    layer_show('编辑',showUrl+data.id,570,400)
                }
            });
        });
    </script>
</th:block>
</html>